package com.xiaoyi.intentsdklibrary.SDK.Action;

import android.app.ActivityManager;
import android.app.KeyguardManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.ClipboardManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.nfc.NfcAdapter;
import android.os.Build;
import android.os.PowerManager;
import android.os.Process;
import android.os.Vibrator;
import android.provider.Settings;
import android.speech.tts.TextToSpeech;
import android.telephony.PhoneNumberUtils;
import com.xiaoyi.intentsdklibrary.FlashUtils;
import com.lkx.liandianqinew.R;
import com.xiaoyi.intentsdklibrary.Utils.NoticUtil;
import com.youyi.yypermissionlibrary.core.os.SettingPage;
import com.zhy.http.okhttp.OkHttpUtils;
import java.io.File;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Locale;

public class ActionNormalSDK {
    private static MediaPlayer mediaPlayer;
    private static MediaPlayer mediaPlayerAlarm;
    private static final ActionNormalSDK ourInstance = new ActionNormalSDK();
    private static Vibrator vibratorAlarm;
    private FlashUtils mFlashUtils;
    private Intent mIntent;
    private TextToSpeech mTextToSpeech;
    private Vibrator mVibrate;

    public static ActionNormalSDK getInstance() {
        return ourInstance;
    }

    private ActionNormalSDK() {
    }

    public void controlWifi(Context context, boolean z) {
        ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).setWifiEnabled(z);
    }

    public boolean isScreenPortrait(Context context) {
        return context.getResources().getConfiguration().orientation != 2;
    }

    public void controlBlueTooth(Context context, boolean z) {
        BluetoothAdapter adapter = ((BluetoothManager) context.getSystemService("bluetooth")).getAdapter();
        if (adapter == null) {
            return;
        }
        if (z) {
            adapter.enable();
        } else {
            adapter.disable();
        }
    }

    public void controlFlow(Context context, boolean z) {
        try {
            ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            connectivityManager.getClass().getMethod("setMobileDataEnabled", Boolean.TYPE).invoke(connectivityManager, Boolean.valueOf(z));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void openAPp(Context context, String str, boolean z) {
        try {
            Intent launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage(str);
            this.mIntent = launchIntentForPackage;
            if (z) {
                launchIntentForPackage.addFlags(335544320);
            } else {
                launchIntentForPackage.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            context.startActivity(this.mIntent);
        } catch (Exception unused) {
        }
    }

    public void stopApp(Context context, String str) {
        for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses()) {
            if (runningAppProcessInfo.processName.equals(str)) {
                Process.killProcess(runningAppProcessInfo.pid);
            }
        }
    }

    public static void installApk(Context context, String str) {
        try {
            File file = new File(str);
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            intent.addCategory("android.intent.category.DEFAULT");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
            context.startActivity(intent);
        } catch (Exception unused) {
        }
    }

    public void unInstallAPP(Context context, String str) {
        try {
            context.startActivity(new Intent("android.intent.action.DELETE", Uri.fromParts(SettingPage.EXTRA_PKG, str, null)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void closeNotification(Context context) {
        Method method;
        try {
            Object systemService = context.getSystemService("statusbar");
            if (Build.VERSION.SDK_INT <= 16) {
                method = systemService.getClass().getMethod("collapse", new Class[0]);
            } else {
                method = systemService.getClass().getMethod("collapsePanels", new Class[0]);
            }
            method.invoke(systemService, new Object[0]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void expandNotification(Context context) {
        Method method;
        Object systemService = context.getSystemService("statusbar");
        if (systemService != null) {
            try {
                Class<?> cls = Class.forName("android.app.StatusBarManager");
                if (Build.VERSION.SDK_INT <= 16) {
                    method = cls.getMethod("expand", new Class[0]);
                } else {
                    method = cls.getMethod("expandSettingsPanel", new Class[0]);
                }
                method.setAccessible(true);
                method.invoke(systemService, new Object[0]);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void gotoSettingMemory(Context context) {
        try {
            Intent intent = new Intent("android.settings.MEMORY_CARD_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSetingWifi(Context context) {
        try {
            Intent intent = new Intent("android.settings.WIFI_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSetingFLy(Context context) {
        try {
            Intent intent = new Intent("android.settings.AIRPLANE_MODE_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSetingNFC(Context context) {
        try {
            Intent intent = new Intent("android.settings.NFC_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSettingGPS(Context context) {
        Intent intent = new Intent();
        intent.setAction("android.settings.LOCATION_SOURCE_SETTINGS");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            context.startActivity(intent);
        } catch (Exception unused) {
            intent.setAction("android.settings.SETTINGS");
            context.startActivity(intent);
        }
    }

    private void gotoSettingNFC(Context context) {
        try {
            NfcAdapter defaultAdapter = NfcAdapter.getDefaultAdapter(context);
            if (defaultAdapter != null && !defaultAdapter.isEnabled()) {
                context.startActivity(new Intent("android.settings.NFC_SETTINGS"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSettingAppList(Context context) {
        try {
            Intent intent = new Intent("android.settings.MANAGE_ALL_APPLICATIONS_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSystemSetting(Context context) {
        try {
            Intent intent = new Intent("android.settings.SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSettingReservice(Context context) {
        try {
            Intent intent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSettingFly(Context context) {
        try {
            Intent intent = new Intent("android.settings.AIRPLANE_MODE_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSettingDeveloper(Context context) {
        try {
            Intent intent = new Intent("android.settings.APPLICATION_DEVELOPMENT_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoFloatPermissionSetting(Context context) {
        try {
            Intent intent = new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION");
            intent.setData(Uri.parse("package:" + context.getPackageName()));
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoAssibilityPermissionSetting(Context context) {
        try {
            Intent intent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(335544320);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoOpenNotic(Context context) {
        NoticUtil.toSetting(context);
    }

    public void ringAndVibrateModel(Context context) {
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        audioManager.setRingerMode(2);
        audioManager.setVibrateSetting(0, 1);
        audioManager.setVibrateSetting(1, 1);
    }

    public void vibrateModel(Context context) {
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        audioManager.setRingerMode(1);
        audioManager.setVibrateSetting(0, 1);
        audioManager.setVibrateSetting(1, 1);
    }

    public void noRingAndVibrateModel(Context context) {
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        audioManager.setRingerMode(0);
        audioManager.setVibrateSetting(0, 0);
        audioManager.setVibrateSetting(1, 0);
    }

    public void openLight(Context context) {
        if (this.mFlashUtils == null) {
            this.mFlashUtils = new FlashUtils(context);
        }
        this.mFlashUtils.open();
    }

    public void closeLight(Context context) {
        if (this.mFlashUtils == null) {
            this.mFlashUtils = new FlashUtils(context);
        }
        this.mFlashUtils.close();
    }

    public void controlVolume(Context context, int i) {
        int i2 = 0;
        if (i < 0) {
            i = 0;
        }
        if (i > 100) {
            i = 100;
        }
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        audioManager.getStreamVolume(3);
        int streamMaxVolume = audioManager.getStreamMaxVolume(3);
        int i3 = (i * streamMaxVolume) / 100;
        if (i3 < streamMaxVolume) {
            streamMaxVolume = i3;
        }
        if (streamMaxVolume > 0) {
            i2 = streamMaxVolume;
        }
        audioManager.setStreamVolume(3, i2, 1);
    }

    public static boolean isAutoBrightness(Context context) {
        try {
            if (Settings.System.getInt(context.getContentResolver(), "screen_brightness_mode") == 1) {
                return true;
            }
            return false;
        } catch (Settings.SettingNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }

    public static void stopAutoBrightness(Context context) {
        Settings.System.putInt(context.getContentResolver(), "screen_brightness_mode", 0);
    }

    public static void startAutoBrightness(Context context) {
        Settings.System.putInt(context.getContentResolver(), "screen_brightness_mode", 1);
    }

    public static void saveBrightness(Context context, int i) {
        stopAutoBrightness(context);
        ContentResolver contentResolver = context.getContentResolver();
        Uri uriFor = Settings.System.getUriFor("screen_brightness");
        Settings.System.putInt(contentResolver, "screen_brightness", i);
        contentResolver.notifyChange(uriFor, null);
    }

    public void sendMsg(Context context, String str, String str2) {
        String replaceAll = str.replaceAll(" ", "");
        if (PhoneNumberUtils.isGlobalPhoneNumber(replaceAll)) {
            Intent intent = new Intent("android.intent.action.SENDTO", Uri.parse("smsto:" + replaceAll));
            this.mIntent = intent;
            intent.putExtra("sms_body", str2);
            this.mIntent.addFlags(335544320);
            context.startActivity(this.mIntent);
        }
    }

    public void call(Context context, String str) {
        try {
            this.mIntent = new Intent("android.intent.action.CALL");
            this.mIntent.setData(Uri.parse("tel:" + str));
            this.mIntent.addFlags(335544320);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void sendMail(Context context, String str, String str2, String str3) {
        try {
            Intent intent = new Intent("android.intent.action.SENDTO");
            this.mIntent = intent;
            intent.setData(Uri.parse("mailto:" + str));
            this.mIntent.putExtra("android.intent.extra.SUBJECT", str2);
            this.mIntent.putExtra("android.intent.extra.TEXT", str3);
            this.mIntent.addFlags(335544320);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void clickVoice(Context context) {
        try {
            if (mediaPlayer == null) {
                mediaPlayer = MediaPlayer.create(context, R.raw.pointsound);
            }
            mediaPlayer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void vibrate(Context context, int i) {
        try {
            if (this.mVibrate == null) {
                this.mVibrate = (Vibrator) context.getSystemService("vibrator");
            }
            this.mVibrate.vibrate((long) i);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void toolWxFu(Context context) {
        try {
            Intent intent = new Intent("com.tencent.mm.ui.ShortCutDispatchAction");
            this.mIntent = intent;
            intent.setPackage("com.tencent.mm");
            this.mIntent.putExtra("LauncherUI.Shortcut.LaunchType", "launch_type_offline_wallet");
            this.mIntent.addFlags(335544320);
            context.startActivity(this.mIntent);
        } catch (Exception unused) {
        }
    }

    public void toolWxZxing(Context context) {
        try {
            Intent launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
            this.mIntent = launchIntentForPackage;
            launchIntentForPackage.putExtra("LauncherUI.From.Scaner.Shortcut", true);
            this.mIntent.addFlags(335544320);
            context.startActivity(this.mIntent);
        } catch (Exception unused) {
        }
    }

    public void toolZfbCode(Context context) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("alipayqr://platformapi/startapp?saId=20000056"));
            this.mIntent = intent;
            intent.addFlags(335544320);
            context.startActivity(this.mIntent);
        } catch (Exception unused) {
        }
    }

    public void openZfbShou(Context context) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("alipayqr://platformapi/startapp?saId=20000123"));
            this.mIntent = intent;
            intent.addFlags(335544320);
            context.startActivity(this.mIntent);
        } catch (Exception unused) {
        }
    }

    public void openZfbZxing(Context context) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("alipayqr://platformapi/startapp?saId=10000007"));
            this.mIntent = intent;
            intent.addFlags(335544320);
            context.startActivity(this.mIntent);
        } catch (Exception unused) {
        }
    }

    public void toolBaidu(Context context) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW");
            this.mIntent = intent;
            intent.addFlags(335544320);
            this.mIntent.setData(Uri.parse("http://baidu.com"));
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void toolBaiduLanguage(Context context) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW");
            this.mIntent = intent;
            intent.addFlags(335544320);
            this.mIntent.setData(Uri.parse("http://fanyi.baidu.com/?aldtype=16047#auto/zh"));
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void wakeUpAndUnlock(Context context) {
        PowerManager powerManager = (PowerManager) context.getSystemService("power");
        if (!powerManager.isScreenOn()) {
            PowerManager.WakeLock newWakeLock = powerManager.newWakeLock(268435466, "bright");
            newWakeLock.acquire(OkHttpUtils.DEFAULT_MILLISECONDS);
            newWakeLock.release();
        }
        KeyguardManager.KeyguardLock newKeyguardLock = ((KeyguardManager) context.getSystemService("keyguard")).newKeyguardLock("unLock");
        newKeyguardLock.reenableKeyguard();
        newKeyguardLock.disableKeyguard();
    }

    public void wakeUp(Context context) {
        try {
            wakeUpAndUnlock(context);
            PowerManager powerManager = (PowerManager) context.getSystemService("power");
            KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService("keyguard");
            PowerManager.WakeLock newWakeLock = powerManager.newWakeLock(268435466, "bright");
            KeyguardManager.KeyguardLock newKeyguardLock = keyguardManager.newKeyguardLock("");
            if (!powerManager.isScreenOn()) {
                newWakeLock.acquire();
            }
            if (Build.VERSION.SDK_INT < 22) {
                return;
            }
            if (keyguardManager.isDeviceLocked()) {
                newWakeLock.release();
            } else if (keyguardManager.inKeyguardRestrictedInputMode()) {
                newKeyguardLock.disableKeyguard();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setCopyText(Context context, String str) {
        ((ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)).setText(str);
    }

    public String getPastText(Context context) {
        return ((ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)).getPrimaryClip().getItemAt(0).getText().toString();
    }

    public void openWeb(Context context, String str) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW");
            this.mIntent = intent;
            intent.addFlags(335544320);
            this.mIntent.setData(Uri.parse(str));
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void talkQQ(Context context, String str) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("mqqwpa://im/chat?chat_type=wpa&uin=" + str));
            this.mIntent = intent;
            intent.addFlags(335544320);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public boolean openUrlScheme(Context context, String str) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(str));
            this.mIntent = intent;
            intent.addFlags(335544320);
            context.startActivity(this.mIntent);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public void sendEmail(Context context, String str, String str2, String str3) {
        try {
            Intent intent = new Intent("android.intent.action.SENDTO");
            this.mIntent = intent;
            intent.setData(Uri.parse("mailto:" + str));
            this.mIntent.putExtra("android.intent.extra.SUBJECT", str2);
            this.mIntent.putExtra("android.intent.extra.TEXT", str3);
            this.mIntent.addFlags(335544320);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void speakText(Context context, final String str) {
        try {
            TextToSpeech textToSpeech = this.mTextToSpeech;
            if (textToSpeech == null) {
                this.mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
                    /* class com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK.AnonymousClass1 */

                    public void onInit(int i) {
                        TextToSpeech unused = ActionNormalSDK.this.mTextToSpeech;
                        if (i == 0) {
                            ActionNormalSDK.this.mTextToSpeech.setLanguage(Locale.CHINA);
                            ActionNormalSDK.this.mTextToSpeech.speak(str, 1, null);
                        }
                    }
                });
            } else {
                textToSpeech.speak(str, 1, null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void alarmVioce(Context context) {
        try {
            if (vibratorAlarm == null) {
                vibratorAlarm = (Vibrator) context.getSystemService("vibrator");
            }
            vibratorAlarm.vibrate(new long[]{1000, 2000, 3000, 4000}, 0);
            if (mediaPlayerAlarm == null) {
                mediaPlayerAlarm = MediaPlayer.create(context, R.raw.kanon);
            }
            mediaPlayerAlarm.start();
            mediaPlayerAlarm.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                /* class com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK.AnonymousClass2 */

                public void onCompletion(MediaPlayer mediaPlayer) {
                    ActionNormalSDK.mediaPlayerAlarm.start();
                    ActionNormalSDK.mediaPlayerAlarm.setLooping(true);
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void stopAlarmVioce() {
        try {
            Vibrator vibrator = vibratorAlarm;
            if (vibrator != null) {
                vibrator.cancel();
            }
            MediaPlayer mediaPlayer2 = mediaPlayerAlarm;
            if (mediaPlayer2 != null) {
                mediaPlayer2.pause();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoFloatSetting(Context context) {
        try {
            Intent intent = new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Intent intent2 = this.mIntent;
            intent2.setData(Uri.parse("package:" + context.getPackageName()));
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoAsSetting(Context context) {
        try {
            Intent intent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoNoticSetting(Context context) {
        try {
            Intent intent = new Intent();
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            if (Build.VERSION.SDK_INT >= 26) {
                this.mIntent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                this.mIntent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName());
            }
            if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 26) {
                this.mIntent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                this.mIntent.putExtra("app_package", context.getPackageName());
                this.mIntent.putExtra("app_uid", context.getApplicationInfo().uid);
            }
            if (Build.VERSION.SDK_INT < 21) {
                this.mIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                this.mIntent.setData(Uri.fromParts(SettingPage.EXTRA_PKG, context.getPackageName(), null));
            }
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSystemPermissionSetting(Context context) {
        try {
            Intent intent = new Intent("android.settings.action.MANAGE_WRITE_SETTINGS", Uri.parse("package:" + context.getPackageName()));
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoSelfSetting(Context context) {
        try {
            Intent intent = new Intent();
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            if (Build.VERSION.SDK_INT >= 9) {
                this.mIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                this.mIntent.setData(Uri.fromParts(SettingPage.EXTRA_PKG, context.getPackageName(), null));
            } else if (Build.VERSION.SDK_INT <= 8) {
                this.mIntent.setAction("android.intent.action.VIEW");
                this.mIntent.setClassName("com.android.settings", "com.android.setting.InstalledAppDetails");
                this.mIntent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName());
            }
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gotoPermissionSetting(Context context, String str) {
        try {
            Intent intent = new Intent();
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            if (Build.VERSION.SDK_INT >= 9) {
                this.mIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                this.mIntent.setData(Uri.fromParts(SettingPage.EXTRA_PKG, str, null));
            } else if (Build.VERSION.SDK_INT <= 8) {
                this.mIntent.setAction("android.intent.action.VIEW");
                this.mIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
                this.mIntent.putExtra("com.android.settings.ApplicationPkgName", str);
            }
            context.startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
            gotoSelfSetting(context);
        }
    }

    public boolean checkPackName(Context context, String str) {
        List<PackageInfo> installedPackages = context.getPackageManager().getInstalledPackages(0);
        if (installedPackages != null) {
            for (int i = 0; i < installedPackages.size(); i++) {
                if (installedPackages.get(i).packageName.equals(str)) {
                    return true;
                }
            }
        }
        return false;
    }

    public void openByMarket(Context context, String str) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + str));
            intent.addFlags(335544320);
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
